﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DLV.Library.Utilities;
using System.Web;
using DLV.Data.Entities;
using System.Web.UI.WebControls;
using System.Drawing;

namespace DLV.FrameWork
{
    public class AdminPageBase : System.Web.UI.Page
    {
        public AdminUserInfo UserInfo
        {
            get
            {
                return AdminUserController.GetCurrentAdminUser();
            }
        }

        public int UserId
        {
            get { return UserInfo.UserID; }
        }

        protected override void OnPreInit(EventArgs e)
        {
            var page = Request.CurrentExecutionFilePath;
            if (Request.QueryString["xml"] != null)
                page += "?xml=" + Request.QueryString["xml"];
            if (UserInfo.IsAdministrator == false)
            {
                if (!(page.ToLower().Contains("/default") || page.ToLower().Contains("/changepassword")))
                {
                    if (UserInfo.IsInPage(page) == false)
                    {
                        Response.Redirect("/AccessDeny.aspx", true);
                        return;
                    }
                }
            }
            MasterPageFile = "/MasterPage.Master";
            base.OnPreInit(e);
        }       
    }
}
